﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JMY_Models;
using JMY_BLL;
using LPY.LeHealth.WebSite.Common;
using Newtonsoft.Json;

namespace HospitalsClient.Controllers
{
    public class HosClientController : Controller
    {
        FindHospitalBLL bll = new FindHospitalBLL();
        // GET: HosClient
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 显示主页信息
        /// </summary>
        /// <returns></returns>
        public ActionResult MainShow()
        {
            var data = new JMY_BLL.MainShowBLL().GetComboInfo();
            ViewBag.list=data;
            return View();
        }
        /// <summary>
        /// 找医院
        /// </summary>
        /// <returns></returns>
        public ActionResult FindHospital()
        {
            return View();
        }
        /// <summary>
        /// 找套餐
        /// </summary>
        /// <returns></returns>
        public ActionResult FindCombo()
        {
            return View();
        }
        /// <summary>
        /// 团体体检
        /// </summary>
        /// <returns></returns>
        public ActionResult GroupCheck()
        {
            return View();
        }
        /// <summary>
        /// 报告管理
        /// </summary>
        /// <returns></returns>
        public ActionResult Repotr()
        {
            return View();
        }
        /// <summary>
        /// 我的信息
        /// </summary>
        /// <returns></returns>
        public ActionResult MyInfos()
        {
            return View();
        }
        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        public ActionResult LoingInfo()
        {
            return View();
        }
        //注册页面
        public ActionResult Result()
        {
            return View();
        }
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult SendSms(string phone)
        {
            var code = LPY.LeHealth.WebSite.Common.SecurityHelper.CreateCode(6);
            Session[phone] = code;
            Session["code"] = code;
            Session.Timeout = 10;
            var msg = SmsHelper.SendSecurityCode(phone,code);
            
            return Json(msg);
        }
        /// <summary>
        /// 注册方法
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="pwd"></param>
        /// <param name="yzm"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Register(string phone, string pwd,string yzm)
        {
            T_User_Infos_Model s = new T_User_Infos_Model();
            s.T_User_Phone = phone;
            s.T_User_Pwd = pwd;
            if (yzm == Session["code"].ToString())
            {
                var data = new JMY_BLL.LoginBLL().LoginsInfo(s);
                if (data > 0)
                {
                    return Json(new { code = 1, Message = "注册成功" });
                }
                else
                {
                    return Json(new { code = 0, Message = "注册失败" });
                }
            }
            else
            {
                return Json(new { code = 0, Message = "验证码有误" });
            }

        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult UserLogins(string phone, string pwd)
        {
            T_User_Infos_Model s = new T_User_Infos_Model();
            s.T_User_Phone = phone;
            s.T_User_Pwd = pwd;
            var data = new JMY_BLL.LoginBLL().UserLogin(s);
            if (data > 0)
            {
                Session["UserName"] = phone;
                return Json(new { code = 1, Message = "登录成功" });
            }
            else
            {
                return Json(new { code = 0, Message = "注册失败" });
            }
        }
        /// <summary>
        /// 我的订单
        /// </summary>
        /// <returns></returns>
        public ActionResult MyCombo(int ids=0)
        {
            string userphone = Convert.ToString(Session["UserName"]);
            if (userphone=="")
            {
                return Content("<script>alert('请先登录');location.href='/HosClient/LoingInfo'</script>");
            }
            else
            {
                

                var data = new JMY_BLL.MyDingDanBLL().GetDingDan(ids, userphone);
                ViewBag.lists = data;
            }
            
            return View();
        }
        /// <summary>
        /// 我的优惠券
        /// </summary>
        /// <returns></returns>
        public ActionResult YouHui()
        {
            return View();
        }
        public ActionResult Tuichu()
        {
            Session.Clear();
            return Content("<script>alert('退出成功');location.href='/HosClient/MyInfos'</script>");
        }

        /// <summary>
        /// 显示医院列表数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string FindHospitalShow()
        {
            List<T_Hospital_Infos> list = bll.InfosShow();
            return JsonConvert.SerializeObject(list);
        }
        /// <summary>
        /// 显示医院二级页面
        /// </summary>
        /// <returns></returns>
        public ActionResult HospitalDetails()
        {
            return View();
        }
        [HttpPost]
        public string ComboShow()
        {
            List<T_Doctor_Combo_Model> list = bll.ComboShow();
            return JsonConvert.SerializeObject(list);
        }
        /// <summary>
        /// 发现页面
        /// </summary>
        /// <returns></returns>
        public ActionResult DocDiscount()
        {
            return View();
        }

        public ActionResult jiankang()
        {
            return View();
        }



    }
}